package Classes
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class ConfigManager extends EventDispatcher
	{
		private var m_config:Object;
		
		public function ConfigManager()
		{
		}
		
		public function load(configLoc:String):void{
			var urlLoader:URLLoader = new URLLoader(new URLRequest(configLoc));
			urlLoader.addEventListener(Event.COMPLETE, onLoadComplete);
		}
		
		private function onLoadComplete(e:Event):void{
			var urlLoader:URLLoader = e.currentTarget as URLLoader;
			m_config = Util.xml2obj(new XML(urlLoader.data));
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		public function getEntities():Array{
			return m_config.children.entities[0].children.entity;
		}
		
		public function getEntityByName(name:String):Object{
			return m_config.children.entities[0].childrenByName[name];
		}
		
		public function getSkillConfigByName(skillName:String):Object{
			return m_config.children.skills[0].childrenByName[skillName];
		}
		

	}
}